jQuery(function($) {
  var html = '<div align="center">'
    + '<div id="ap_bottombar" align="center" style="margin: 5px auto; width: 580px; padding: 2px;" class="ui-widget ui-widget-content ui-corner-all">'
    + '<span class="ui-icon ui-icon-search" style="float: left; margin-top: 2px;"></span>'
    + '<label><input type="radio" name="ap_spid_opt" class="ap_spid_opt" value="s" checked="checked" />'
    + 'System ID</label> |'
    + '<label><input type="radio" name="ap_spid_opt" class="ap_spid_opt" value="p" />'        
    + 'Player ID</label> '
    + '<input id="ap_spid" type="text" size="7" class="text" /> '
    + '<input id="ap_spid_show" type="button" value="Find" class="ui-state-default ui-corner-all" />'
    + '</div></div>';

  $('body:has(#awplus_navbar)').append(html);
  
  $('#ap_spid').keyup(function(e) {
    if (e.keyCode == 13) {
      $('#ap_spid_show').trigger('click');
    }
  })
  
  $('#ap_spid_show').click(function() {
    var id = $.trim($('#ap_spid').val());
    if (id == '') {
      alert('Pleases, add ID value.');
      $('#ap_spid')[0].focus();
      return;
    }
    
    if ($('.ap_spid_opt:checked').val() == 's') {
      awPlus.showSystemDialog(id, 'center');
    }
    else if ($('.ap_spid_opt:checked').val() == 'p') {
      awPlus.showPlayerDialog(id, 'center');
    }
    else {
      alert('Han?');
    }
  });
});
